<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        class Person {
            constructor(name) {
                this.name = name;
                this.maxAge = 100
            }
            // get 后面时被监听的属性名.会拦截访问操作，最终得到的值以函数返回值为准
            get name () {
                console.log('访问了name属性');
                return '666'
            }
            // 给name属性赋值时调用这个函数
            set name(val) {
                console.log('设置了name属性');
            }
        }

        let zzg = new Person('Mabaoguo');
        console.log(zzg.name);
    </script>
</body>
</html>